# -*- coding: utf-8 -*-
# Gestión gráfica del código principal de módulo.

## vipera, un diseñador de aplicaciones para Python
##     Copyright (C) 2011 Ángel Luis García García
##
##    This program is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import wx

from clases_marcos_vista import panel_prin
from editor2_vipera import panel_codigo_ed
from i18n_vipera import t

class panel_prin_p(panel_prin):
    '''Panel de código principal de módulo'''
    def __init__(self, parent, idioma = None):
        '''Constructor de clase'''        
        panel_prin.__init__(self, parent)
        # Cambiamos idioma al widget de wxFB.
        self.m_checkBox_eje.SetLabel(t(u'Ejecutar código', idioma))
        indentacion = 4
        self.editor = panel_codigo_ed(self.m_panel_ejecucion, indentacion, idioma = idioma)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.editor, 1, wx.ALL|wx.EXPAND, 5)
        self.m_panel_ejecucion.SetSizer(sizer)

    def limpiar_widget(self):
        '''Limpiar widgets'''
        self.editor.panel.editor.SetText('')
        self.m_checkBox_eje.Set3StateValue(wx.CHK_UNCHECKED)
        
    def salvar_datos(self):
        '''Método que recorre el código de módulo y lo devuelve en un diccionario'''                
        codigo_p = self.editor.panel.editor.GetText()
        codigo_p_eje = self.m_checkBox_eje.Get3StateValue()
        codigo_modulo = {'codigo_p' : codigo_p,
                         'codigo_p_eje' : codigo_p_eje}
        # Devolvemos diccionario.
        return codigo_modulo
        
    def cargar_datos(self, codigo_p):
        '''Cargamos código principal de módulo en widget'''
        self.editor.panel.editor.SetText(codigo_p['codigo_p'])
        self.m_checkBox_eje.Set3StateValue(codigo_p['codigo_p_eje'])
    